package com.epfresh.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.api.universalimageloader.core.ImageLoader;
import com.epfresh.api.universalimageloader.core.imageaware.ImageViewAware;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.bean.OrderListBean;
import com.epfresh.global.BaseApplication;
import com.epfresh.wxapi.pay.weipay.Util;

import java.util.List;

/**
 * Created by zzq on 2016/7/19.
 */
public class OrderAdapter extends BaseAdapter implements View.OnClickListener {

    public ListView lv;
    public Context context;
    public List<OrderListBean> list;
    private AdapterView.OnItemClickListener onItemClickListener;

    public AdapterView.OnItemClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public OrderAdapter(Context context, ListView lv, List<OrderListBean> groupList) {
        this.context = context;
        this.list = groupList;
        this.lv = lv;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int groupPosition, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list_order_more, null, false);
            vh.tv_order_id = (TextView) convertView.findViewById(R.id.tv_order_id);
            vh.tv_freight_end = (TextView) convertView.findViewById(R.id.tv_freight_end);

            vh.tv_market = (TextView) convertView.findViewById(R.id.tv_market);

            vh.tv_post_type = (TextView) convertView.findViewById(R.id.tv_post_type);
            vh.tv_place_time = (TextView) convertView.findViewById(R.id.tv_place_time);
            vh.iv_logo = (ImageView) convertView.findViewById(R.id.iv_logo);
            vh.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            vh.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            vh.iv_promotion = (ImageView) convertView.findViewById(R.id.iv_promotion);
            vh.ll_images = (LinearLayout) convertView.findViewById(R.id.ll_images);
            vh.rl_more = convertView.findViewById(R.id.rl_more);
            vh.rl_only_one = convertView.findViewById(R.id.rl_only_one);
            vh.tv_code = (TextView) convertView.findViewById(R.id.tv_code);
            vh.tv_logistics = (TextView) convertView.findViewById(R.id.tv_logistics);
            vh.tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);
            vh.tv_sure = (TextView) convertView.findViewById(R.id.tv_sure);
            vh.tv_pay = (TextView) convertView.findViewById(R.id.tv_pay);
            vh.tv_evaluate = (TextView) convertView.findViewById(R.id.tv_evaluate);


            vh.tv_more = (TextView) convertView.findViewById(R.id.tv_more);
            vh.tv_total_left=(TextView)convertView.findViewById(R.id.tv_total_left);
            vh.tv_total_kind = (TextView) convertView.findViewById(R.id.tv_total_kind);
            vh.tv_total_money = (TextView) convertView.findViewById(R.id.tv_total_money);
            vh.ll_order = convertView.findViewById(R.id.ll_order);


            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_pay.setTag(R.id.item_key_position, groupPosition);
        vh.tv_code.setTag(R.id.item_key_position, groupPosition);
        vh.tv_logistics.setTag(R.id.item_key_position, groupPosition);
        vh.tv_cancel.setTag(R.id.item_key_position, groupPosition);
        vh.tv_sure.setTag(R.id.item_key_position, groupPosition);
        vh.tv_evaluate.setTag(R.id.item_key_position, groupPosition);

        vh.tv_more.setTag(R.id.item_key_position, groupPosition);
        vh.ll_images.setTag(R.id.item_key_position, groupPosition);
        vh.ll_images.setOnClickListener(this);
        vh.ll_order.setTag(R.id.item_key_position, groupPosition);
        vh.ll_order.setOnClickListener(this);

        OrderListBean order = list.get(groupPosition);
        vh.tv_order_id.setText("订单：" + order.getOrderNo());
        vh.tv_place_time.setText(order.getPlaceOrderTime());

        //设置店铺名称和订单状态
        if (order.getWholeSaleMarketTitle() != null) {
            if (order.getWholeSaleMarketTitle().length() > 17) {
                vh.tv_market.setText(order.getWholeSaleMarketTitle().substring(0, 17) + "...");
            } else {
                vh.tv_market.setText(order.getWholeSaleMarketTitle());
            }
        } else {
            vh.tv_market.setText("");
        }


//        vh.tv_market.setText(order.getWholeSaleMarketTitle());

        vh.tv_post_type.setText(order.getPurchaseStatusTitle());////

        if (order.isShowPrice()) {
            vh.tv_total_kind.setText("共" + order.getProductCount() + "件");
            vh.tv_total_left.setVisibility(View.GONE);
            vh.tv_total_kind.setVisibility(View.VISIBLE);
            vh.tv_total_money.setText("订单金额：" + order.getOrderSumPrice() + "元");
            vh.tv_freight_end.setText("(" + "含运费：" + order.getProductExpressFee() + "元)");
        } else {
            vh.tv_total_left.setText("共" + order.getProductCount() + "件");
            vh.tv_total_left.setVisibility(View.VISIBLE);
            vh.tv_total_kind.setVisibility(View.GONE);
            vh.tv_total_money.setText("");
            vh.tv_freight_end.setText("");
        }


        vh.tv_post_type.setTag(R.id.item_key_position, groupPosition);
        vh.tv_post_type.setOnClickListener(this);

        if (order.getResult().size() > 1) {
            vh.rl_more.setVisibility(View.VISIBLE);
            vh.rl_only_one.setVisibility(View.GONE);
            addImages(vh.ll_images, list.get(groupPosition));
        } else if (order.getResult().size() == 1) {
            vh.rl_more.setVisibility(View.GONE);
            vh.rl_only_one.setVisibility(View.VISIBLE);
            if (2 == (order.getResult().get(0).getSalesType())) {//预售
                vh.tv_type.setVisibility(View.VISIBLE);
                String html = "<font color=\"#00ffffff\">【预售】</font>" + order.getResult().get(0).getProductTitle();
                vh.tv_title.setText(Html.fromHtml(html));
            } else {//现售
                vh.tv_type.setVisibility(View.GONE);
                vh.tv_title.setText(order.getResult().get(0).getProductTitle());
            }

            ImageLoader.getInstance().displayImage(order.getResult().get(0).getProductImgUrl(), vh.iv_logo);

            String promotionMarkUrl = order.getResult().get(0).getMarkUrl();
            ImageLoader.getInstance().displayImage(promotionMarkUrl, new ImageViewAware(vh.iv_promotion), BaseApplication.getTagOptions(promotionMarkUrl), null, null, null);

        }

        initBottom(list.get(groupPosition).getButtonType(), vh,list.get(groupPosition).getDeliveryType());

        convertView.setTag(vh);
        convertView.setClickable(true);
        return convertView;
    }

    public class ViewHolder {
        TextView tv_freight_end;


        TextView tv_market;
        TextView tv_post_type;
        TextView tv_place_time;
        TextView tv_order_id;

        TextView tv_total_kind,tv_total_left;
        TextView tv_total_money;

        ImageView iv_logo;
        ImageView iv_promotion;

        TextView tv_type;
        TextView tv_title;
        LinearLayout ll_images;

        View rl_more, rl_only_one;

        View ll_order;

        TextView tv_code;
        TextView tv_logistics;
        TextView tv_cancel;
        TextView tv_sure;
        TextView tv_pay;
        TextView tv_evaluate;
        TextView tv_more;

    }


    void addImages(LinearLayout v, OrderListBean imagesList) {
        v.removeAllViews();
        v.setMinimumWidth(LocalDisplay.SCREEN_WIDTH_PIXELS - LocalDisplay.dp2px(30));
        for (int i = 0; i < imagesList.getResult().size(); i++) {
            ImageView flag = new ImageView(context);
            flag.setScaleType(ImageView.ScaleType.CENTER_CROP);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LocalDisplay.dp2px(50), LocalDisplay.dp2px(50));
            flag.setLayoutParams(lp);
            LinearLayout.LayoutParams lpFrame = new LinearLayout.LayoutParams(LocalDisplay.dp2px(50), LocalDisplay.dp2px(50));
            ImageLoader.getInstance().displayImage(imagesList.getResult().get(i % imagesList.getResult().size()).getProductImgUrl(), flag);
            FrameLayout f = new FrameLayout(context);
            lpFrame.setMargins(LocalDisplay.dp2px(7), 0, LocalDisplay.dp2px(7), 0);
            if (i == 0) {
                lpFrame.setMargins(LocalDisplay.dp2px(10), 0, LocalDisplay.dp2px(7), 0);
            }
            if (i == imagesList.getResult().size()) {
                lpFrame.setMargins(LocalDisplay.dp2px(7), 0, LocalDisplay.dp2px(10), 0);
            }
            f.setLayoutParams(lpFrame);
            f.addView(flag);
            ImageView tag = new ImageView(context);
            tag.setScaleType(ImageView.ScaleType.CENTER_CROP);
            LinearLayout.LayoutParams tagLp = new LinearLayout.LayoutParams(LocalDisplay.dp2px(30), LocalDisplay.dp2px(33));
            tag.setLayoutParams(tagLp);
            ImageLoader.getInstance().displayImage(imagesList.getResult().get(i % imagesList.getResult().size()).getMarkUrl(), new ImageViewAware(tag), BaseApplication.getTagOptions(imagesList.getResult().get(i % imagesList.getResult().size()).getMarkUrl()), null, null, null);
            f.addView(tag);
            v.addView(f);
        }
    }

    void initBottom(int type, ViewHolder vh, int deliveryType) {
        vh.tv_code.setOnClickListener(this);
        vh.tv_logistics.setOnClickListener(this);
        vh.tv_cancel.setOnClickListener(this);
        vh.tv_sure.setOnClickListener(this);
        vh.tv_pay.setOnClickListener(this);
        vh.tv_evaluate.setOnClickListener(this);
        vh.tv_more.setOnClickListener(this);

        vh.tv_code.setVisibility(View.GONE);
        vh.tv_logistics.setVisibility(View.GONE);
        vh.tv_cancel.setVisibility(View.GONE);
        vh.tv_sure.setVisibility(View.GONE);
        vh.tv_pay.setVisibility(View.GONE);
        vh.tv_evaluate.setVisibility(View.GONE);
        vh.tv_more.setVisibility(View.GONE);

        switch (type) {

            case 1://待付款
                vh.tv_logistics.setVisibility(View.VISIBLE);
                vh.tv_cancel.setVisibility(View.VISIBLE);
                vh.tv_pay.setVisibility(View.VISIBLE);
                break;
            case 2://待发货
                vh.tv_logistics.setVisibility(View.VISIBLE);
                vh.tv_cancel.setVisibility(View.VISIBLE);
                break;
            case 3://待收货
                vh.tv_code.setVisibility(View.VISIBLE);
                if (deliveryType == 6) {
                    vh.tv_code.setVisibility(View.GONE);
                }
                vh.tv_logistics.setVisibility(View.VISIBLE);
                vh.tv_sure.setVisibility(View.VISIBLE);
                break;
            case 4:
                //vh.tv_logistics.setVisibility(View.VISIBLE);
                //vh.tv_code.setVisibility(View.VISIBLE);
                vh.tv_evaluate.setVisibility(View.VISIBLE);
                vh.tv_more.setVisibility(View.VISIBLE);

                break;
            case 5://拒收
                vh.tv_logistics.setVisibility(View.VISIBLE);
                break;
            case 10:
                vh.tv_evaluate.setVisibility(View.VISIBLE);
                break;
            case 11:
                vh.tv_more.setVisibility(View.VISIBLE);
                break;

            case 15://拒收
                vh.tv_more.setVisibility(View.VISIBLE);
                vh.tv_evaluate.setVisibility(View.VISIBLE);
                vh.tv_pay.setVisibility(View.VISIBLE);
                break;
            case 16:
                vh.tv_evaluate.setVisibility(View.VISIBLE);
                vh.tv_pay.setVisibility(View.VISIBLE);
                break;
            case 17:
                vh.tv_pay.setVisibility(View.VISIBLE);
                vh.tv_more.setVisibility(View.VISIBLE);
                break;
            case 22:
                vh.tv_pay.setVisibility(View.VISIBLE);
            default:
                break;
        }
    }


    @Override
    public void onClick(View v) {
        Object tag = v.getTag(R.id.item_key_position);
        if (tag != null && tag instanceof Integer) {
            int position = (int) tag;
            onItemClickListener.onItemClick(null, v, position, position);

// 交货码，查看物流，取消订单，确认收货，支付， 详情
/*            switch (v.getId()) {
                case R.id.tv_code:
                    showCodeDialog(list.get(position).getInspectCode());
                    break;
                case R.id.tv_sure:
                    if(isWindowLocked())
                        return;
                    else
                        mHttpCheck(position);
                    break;
                case R.id.tv_logistics:
                    Intent logisticsInfo = new Intent(context, OrderLogisticsInfoActivity.class);
                    logisticsInfo.putExtra("logisticsNo", list.get(position).getOrderId());
                    context.startActivity(logisticsInfo);
                    break;
                case R.id.tv_pay:
                    if(isWindowLocked())
                        return;
                    else {
                        if (list.get(position).getButtonType() == 1) {
                            Intent pay = new Intent(context, WXPayEntryActivity.class);
                            pay.putExtra("payWay", 1);
                            String orderId = list.get(position).getOrderId();
                            pay.putExtra("orderId", orderId);
                            context.startActivity(pay);
                        } else {
                            mHttpCheck(position);
                        }
                    }
                    break;
                case R.id.tv_cancel:
                    showCancelDialog();
                    break;
                case R.id.tv_order_not_want:
                    dialog.dismiss();
                    if(list==null||list.size()==0){
                        T.toast("请刷新当前页面");
                        return;
                    }
                    if(isWindowLocked())
                        return;
                    else
                        mHttpCancel(list.get(flagPosition).getOrderId(),"不想要了");
                    break;
                case R.id.tv_order_wrong:
                    dialog.dismiss();
                    if(list==null||list.size()==0){
                        T.toast("请刷新当前页面");
                        return;
                    }
                    if(isWindowLocked())
                        return;
                    else
                        mHttpCancel(list.get(flagPosition).getOrderId(),"点错了");
                    break;
                case R.id.v_order_cancel:
                    dialog.dismiss();
                    break;
                case R.id.tv_more:
                    if(isWindowLocked())
                        return;
                    else
                        mHttpMore(flagPosition);
                    break;
                case R.id.tv_evaluate:
                    Intent evaluate = new Intent(context, EvaluateActivity.class);
                    //evaluate.putExtra("goodsList",(Serializable) list.get(flagPosition).getResult());
                    evaluate.putExtra("orderId",list.get(flagPosition).getOrderId());
                    *//*
             * startActivityForResult
             * *//*
                    commonFresh.startActivityForResultCommon(evaluate,0x001);
                    break;
                case R.id.ll_order:
                case R.id.rl_more:
                case R.id.ll_images:
                    Intent detail = new Intent(context,H5OrderDetailActivity.class);
                    detail.putExtra("orderId", list.get(position).getOrderId());
                    detail.putExtra(Constant.KEY_WEB_URL, "http://m.epfresh.com/help/order_detail.html?orderId="+list.get(position).getOrderId());
                    detail.putExtra(Constant.KEY_WEB_TITLE, "订单详情");
                    detail.putExtra("page",type);
                    //((MyOrderActivity)context).startActivityForResult(detail,0x001);
                    commonFresh.startActivityForResultCommon(detail,0x001);

                    break;
            }*/
        }
    }
/*
    private Dialog dialogCancel;
    TextView[] numbers = new TextView[6];
    void showCodeDialog(String code){
        if (dialogCancel == null) {
            View view = LayoutInflater.from(context).inflate(R.layout.dialog_code, null);
            dialogCancel = new Dialog(context, R.style.ActionSheetDialogStyle);
            dialogCancel.setContentView(view);
            Window dialogWindow = dialogCancel.getWindow();
            dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS;
            dialogWindow.setAttributes(lp);
            numbers[0] = (TextView)view.findViewById(R.id.number1);
            numbers[1] = (TextView)view.findViewById(R.id.number2);
            numbers[2] = (TextView)view.findViewById(R.id.number3);
            numbers[3] = (TextView)view.findViewById(R.id.number4);
            numbers[4] = (TextView)view.findViewById(R.id.number5);
            numbers[5] = (TextView)view.findViewById(R.id.number6);
        }
        for(int i=0;i<6;i++){
            numbers[i].setText(""+code.charAt(i));
        }
        dialogCancel.show();
    }

    private Dialog dialog;
    private int flagPosition;
    View view,v_order_cancel,tv_order_not_want,tv_order_wrong;
    public void showCancelDialog() {
        if (dialog == null) {
            view = LayoutInflater.from(context).inflate(R.layout.dialog_order, null);
            v_order_cancel = view.findViewById(R.id.v_order_cancel);
            tv_order_not_want = view.findViewById(R.id.tv_order_not_want);
            tv_order_wrong = view.findViewById(R.id.tv_order_wrong);
            v_order_cancel.setOnClickListener(this);
            tv_order_wrong.setOnClickListener(this);
            tv_order_not_want.setOnClickListener(this);
            dialog = new Dialog(context, R.style.no_title_dialog);
            dialog.setContentView(view);
            Window dialogWindow = dialog.getWindow();
            dialogWindow.setGravity(Gravity.CENTER);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS - LocalDisplay.dp2px(30);
            dialogWindow.setAttributes(lp);
        }
        tv_order_wrong.setTag(R.id.item_key_position, flagPosition);
        v_order_cancel.setTag(R.id.item_key_position, flagPosition);
        tv_order_not_want.setTag(R.id.item_key_position, flagPosition);
        dialog.show();
    }
    *//** 取消订单 *//*
    private void mHttpCancel(String  id,String reason) {
        Log.i("列表测试", "" + id + reason);
        RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
        data.setCmd("appOrder/appCancelOrder");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", id);
        map.put("reason", reason);
        data.setParameters(map);
        ((BaseActivity)context).request(data, "appOrder/appCancelLogisticsOrder", new OnRequestListener<StatusEntity>() {
            @Override
            public StatusEntity jsonToObj(String responseStr) {
                return new Gson().fromJson(responseStr, StatusEntity.class);
            }

            @Override
            public void onFail(int failCode, Object arg, Object tag) {
                Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponseError(int failCode, Object arg, Object tag) {
                ((BaseActivity) context).toast((arg == null ? "" : arg + ""));
            }

            @Override
            public void onStart(Object tag) {
            }

            @Override
            public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
                StatusEntity responseElement = response.getResponseElement();
                if (responseElement.isSuccess()) {
                    //requestOrderInfo();
*//*                    if(type==0) {
                        OrderAdapter.this.list.get(flagPosition).setButtonType(11);
                        OrderAdapter.this.list.get(flagPosition).setPurchaseStatusTitle("交易关闭");
                    }else{
                        OrderAdapter.this.list.remove(flagPosition);
                    }
                    notifyDataSetChanged();*//*
                    commonFresh.intoFresh();
                    T.toast("已取消");
                } else {
                    T.toast("服务器出现小问题，请稍后再试");
                }
            }
        });
    }

    public interface CommonFresh {
        void intoFresh();
        void startActivityForResultCommon(Intent intent, int requestCode);
    }

    *//** 确认收货1 有无尾款 *//*
    class SureCheckBean {
        int type;
        double money;
    }
    private void mHttpCheck(final int id) {
        RequestEntityPurchase<Map<String, Object>> dataRequest = new RequestEntityPurchase<>();
        dataRequest.setCmd("appOrder/checkReceiveGood");

        Map<String, Object> map = new HashMap<>();
        map.put("orderId", this.list.get(id).getOrderId());
        dataRequest.setParameters(map);
        ((BaseActivity)context).request(dataRequest, "appOrder/checkReceiveGood", new OnRequestListener<SureCheckBean>() {
            @Override
            public SureCheckBean jsonToObj(String responseStr) {
                return new Gson().fromJson(responseStr, SureCheckBean.class);
            }

            @Override
            public void onFail(int failCode, Object arg, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponseError(int failCode, Object arg, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                T.toast((arg == null ? "" : arg + ""));
            }

            @Override
            public void onStart(Object tag) {
                ((BaseActivity) context).showProgressDialog();
            }

            @Override
            public void onResponse(ResponseEntity<SureCheckBean> response, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                final SureCheckBean responseElement = response.getResponseElement();
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setMessage("您已经收到货物，验货通过，清点无误！");//设置显示的内容
                if (responseElement.type == 1||responseElement.type == 2) {//0结束；1：收银台，2：有尾款
                    //builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "去收银台付款：" + responseElement.money + "元。");
                    builder.setMessage("您还有未支付钱款，去支付？");
                }*//* else if (responseElement.type == 2) {
                    builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "并且已经付清尾款：" + responseElement.money + "元。");
                }*//*
                builder.setTitle("确认收货？")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {//添加确定按钮
                            @Override
                            public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
                               if(responseElement.type==1||responseElement.type==2){
                                    Intent pay = new Intent(context, WXPayEntryActivity.class);
                                    pay.putExtra("orderId",list.get(id).getOrderId());
                                    pay.putExtra("type","2");
                                    context.startActivity(pay);
                                    return;
                                }else{
                                    mHttpSure(id, responseElement.type);
                                    return;
                                }
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {//添加返回按钮
                    @Override
                    public void onClick(DialogInterface dialog, int which) {//响应事件
                        // TODO Auto-generated method stub
                    }

                }).show();//在按键响应事件中显示此对话框

            }
        });
    }
    *//** 确认收货2 *//*
    private void mHttpSure(int id,int type1) {
        RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
        data.setCmd("appOrder/confirmReceiveGood");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", this.list.get(id).getOrderId());
        map.put("type", ""+type1);
        data.setParameters(map);
        ((BaseActivity)context).request(data, "appOrder/confirmReceiveGood", new OnRequestListener<StatusEntity>() {
            @Override
            public StatusEntity jsonToObj(String responseStr) {
                return new Gson().fromJson(responseStr, StatusEntity.class);
            }

            @Override
            public void onFail(int failCode, Object arg, Object tag) {
                Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponseError(int failCode, Object arg, Object tag) {
                T.toast((arg == null ? "" : arg + ""));
            }

            @Override
            public void onStart(Object tag) {
            }

            @Override
            public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
                StatusEntity responseElement = response.getResponseElement();
                if (responseElement.isSuccess()) {
*//*                    T.toast("收货成功");
                    if(type==0) {
                        OrderAdapter.this.list.get(flagPosition).setButtonType(5);
                        for (int i = 0; i < OrderAdapter.this.list.get(flagPosition).getResult().size(); i++) {
                           OrderAdapter.this.list.get(flagPosition).setPurchaseStatusTitle("交易成功");
                        }
                    }else{
                        OrderAdapter.this.list.remove(flagPosition);
                    }
                    notifyDataSetChanged();*//*
                    commonFresh.intoFresh();
                } else {
                    T.toast("服务器出现小问题，请稍后再试");
                }
            }
        });
    }

    *//** 再来一单 *//*
    private void mHttpMore(int id) {
        RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
        data.setCmd("appOrder/addToShoppingCarAgain");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", list.get(id).getOrderId());
        map.put("accountId",ApplicationHelper.getInstance().getUser().getAccountId());
        map.put("cityId", ApplicationHelper.getInstance().getCity().getCityId());
        data.setParameters(map);
        ((BaseActivity)context).request(data, "appOrder/addToShoppingCarAgain", new OnRequestListener<StatusEntity>() {
            @Override
            public StatusEntity jsonToObj(String responseStr) {
                return new Gson().fromJson(responseStr, StatusEntity.class);
            }

            @Override
            public void onFail(int failCode, Object arg, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                //Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponseError(int failCode, Object arg, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                //T.toast((arg == null ? "" : arg + ""));
            }

            @Override
            public void onStart(Object tag) {
                ((BaseActivity) context).showProgressDialog();
            }

            @Override
            public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
                ((BaseActivity) context).hideProgressDialog();
                Intent intent = new Intent(context,
                        HomeActivity.class);
                intent.putExtra("home_tab_index", 2);
                DataManager.getInstance().isNeedRefreshCart = true;
                context.startActivity(intent);
                notifyDataSetChanged();
            }
        });
    }
    long mLastOnClickTime;
    public boolean isWindowLocked() {
        long current = SystemClock.elapsedRealtime();
        if(current - this.mLastOnClickTime > 1500L) {
            this.mLastOnClickTime = current;
            return false;
        } else {
            return true;
        }
    }*/
}
